import {Service, action} from "adajs";
import List from './../lists';
import PhoneList from "./../lists/phone";

class ContactsService extends Service {
    defaultData() {
        return {
            types: [
                {
                    name: "老同志电话",
                    type: List,
                    active: true,
                    list: {
                        url: "/api/lgb/app/lgb/telephone/queryPage",
                        type: PhoneList,
                        parameter: {lbDm: 3, mc: ''}
                    }
                },
                {
                    name: "工作人员电话",
                    type: List,
                    active: false,
                    list: {
                        url: "/api/lgb/app/lgb/telephone/queryPage",
                        type: PhoneList,
                        parameter: {lbDm: 5,mc:''}
                    }
                },
                {
                    name: "活动站电话",
                    type: List,
                    active: false,
                    list: {
                        url: "/api/lgb/app/lgb/telephone/queryPage",
                        type: PhoneList,
                        parameter: {lbDm: 4, mc: ''}
                    }
                },
                {
                    name: "常用服务电话",
                    type: List,
                    active: false,
                    list: {
                        url: "/api/lgb/app/lgb/telephone/queryPage",
                        type: PhoneList,
                        parameter: {lbDm: 0, mc: ''}
                    }
                },
                {
                    name: "应急电话",
                    type: List,
                    active: false,
                    list: {
                        url: "/api/lgb/app/lgb/telephone/queryPage",
                        type: PhoneList,
                        parameter: {lbDm: 1, mc: ''}
                    }
                }
            ]
        };
    }

    onupdate(current, data) {
        Object.assign(current, data);
    }

    @action("active")
    active(current, type) {
        current.types.forEach(item => {
            if (item.name === type.name) {
                item.active = true;
            } else {
                item.active = false;
            }
        });
    }

    @action("search")
    search(current, keyword) {
        current.types.forEach(type => type.list.parameter.mc = keyword);
    }
}

export default ContactsService;